<!--批量修改岗位系数-->
<template>
  <el-dialog :title="title" :visible.sync="visible" :width="width" :close-on-click-modal='false' class="bonus">
    <el-row>
      <el-form  :model="formData" ref="formRef" :label-width="labelWidth"  :rules="rules" v-loading="formLoading" :close-on-click-modal="false">
        <el-form-item label="原岗位系数" prop="groupName">
          <el-select v-model="formData.oldPostRatio" placeholder="请选择原岗位系数">
            <el-option :value="item.value" :label="item.label" v-for="(item,index) in ratioOptions" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="新岗位系数" prop="postRatio">
          <el-input v-model="formData.postRatio" autocomplete="off" placeholder="请输入新岗位系数" clearable></el-input>
        </el-form-item>
      </el-form>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary"  @click="handleSubmit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addGroupObj, putGroupObj,getPostRatioByDept,updatePostRatioByDept} from '@/api/bonus/calculateorgconfig' ;
export default {
  name: "groupPostRatio",
  components:{
  },
  watch: {

  },
  data(){
    return{
      type:'add',
      formLoading:false,
      title:'批量修改系数',
      width:'30%',
      visible: false,
      labelWidth:'125px',
      formData: {},
      rules: {
        oldPostRatio: [{ required: true, message: '请选择旧系数', trigger: 'change' },],
        postRatio: [{ required: true, message: '请输新系数', trigger: 'blur' },],
      },
      ratioOptions:[]
    }
  },
  methods:{
    init(type,currentGroup){
      this.type = type
      this.getRatioOptions(currentGroup.id)
      this.formData.groupId = currentGroup.id
      this.visible = true ;
    },
    getRatioOptions(groupId){
      getPostRatioByDept(groupId).then(res=>{
          if (res.data.code == 0){
            res.data.data.map(item=>{
               this.ratioOptions.push({label:item,value:item})
            })
          }
      }).catch(err=>{

      })
    },
    handleSubmit(){
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.formLoading = true ;
          updatePostRatioByDept(this.formData).then(res=>{
              this.formLoading = false ;
              this.handleCancel(true) ;
            }).catch(()=>{
              this.formLoading = false ;
            })
        } else {
          return false;
        }
      });
    },
    handleCancel(refresh){
      this.visible = false ;
      this.formData = {} ;
      if (refresh){
        this.$emit('refresh')
      }
      this.ratioOptions = []
      this.$refs.formRef.resetFields() ;
    },

    onChange(){

    }
  }
}
</script>

<style scoped>

</style>

